package com.zeny.xdclass.controller.admin;

import com.zeny.xdclass.common.ResponseResult;
import com.zeny.xdclass.domain.Video;
import com.zeny.xdclass.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName VideoAdminController
 * @Description TODO
 * @Author zeny
 */
@RestController
@RequestMapping("/admin/api/v1/video")
@Api(tags = "视频模块(管理员)")
public class VideoAdminController {

    @Autowired
    private VideoService videoService;

    @ApiOperation(value = "更新视频信息")
    @PutMapping("/update")
    public ResponseResult update(@RequestBody Video video) {
        Integer success = videoService.update(video);
        return success == 1 ? ResponseResult.ok().message("更新成功") : ResponseResult.fail().message("更新失败");
    }

    @ApiOperation(value = "新增视频信息")
    @PostMapping("/save")
    public ResponseResult save(@RequestBody Video video) {
        videoService.save(video);
        return ResponseResult.ok().message("新增成功");
    }

    @ApiOperation(value = "根据ID删除视频")
    @DeleteMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "视频ID", defaultValue = "1", required = true)
    })
    public ResponseResult delete(Integer id) {
        Integer success = videoService.delete(id);
        return success == 1 ? ResponseResult.ok().message("删除成功") : ResponseResult.fail().message("删除失败");
    }
}
